#include "engine.h"

#include <GL/glfw.h>
#include <assert.h>

namespace HW
{

float FPS(void)
{
	extern float gLastFrameDur;
	return 1000.0f / gLastFrameDur;
}

float UPS(void)
{
	//TODO: change this to updates per second.
	return FPS ( );
}

float AppSpeed(void)
{
	return FPS() / 60.0f;
}

float AppTime(void)
{
	extern float gTime;
	return gTime;
}

void UpdateAppTime(void)
{
	extern bool gPaused;
	extern float gTime;

	if ( !gPaused )
	{
		gTime = float( glfwGetTime ( ) * 1000.0 );
	}
}

void PauseApp(void)
{
	//TODO: stop physics and other threads here
	extern bool gPaused;
	extern float gTime;

	if ( !gPaused )
	{
		gPaused = true;
		gTime = float ( glfwGetTime ( ) * 1000.0 );
	}
}

void ResumeApp(void)
{
	//TODO: restart physics and other threads here
	extern bool gPaused;
	extern float gTime;

	if ( gPaused )
	{
		gPaused = false;
		glfwSetTime ( gTime / 1000.0 );
		assert ( gTime != (glfwGetTime()*1000.0f) );
	}
}

int AppSuspended(void)
{
	int lResult = 1 - glfwGetWindowParam ( GLFW_ACTIVE );
	if ( lResult == GL_TRUE )
		glfwPollEvents ( );
	return lResult;
}

}